package com.wy.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wy.system.domain.vo.SysPayVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wy.common.annotation.Log;
import com.wy.common.core.controller.BaseController;
import com.wy.common.core.domain.AjaxResult;
import com.wy.common.enums.BusinessType;
import com.wy.system.domain.SysPay;
import com.wy.system.service.ISysPayService;
import com.wy.common.utils.poi.ExcelUtil;
import com.wy.common.core.page.TableDataInfo;

/**
 * 物业费记录Controller
 * 
 * @author ruoyi
 * @date 2023-03-03
 */
@RestController
@RequestMapping("/system/pay")
public class SysPayController extends BaseController
{
    @Autowired
    private ISysPayService sysPayService;

    /**
     * 查询物业费记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPay sysPay)
    {
        startPage();
        List<SysPayVo> list = sysPayService.selectSysPayList(sysPay);
        return getDataTable(list);
    }

    /**
     * 导出物业费记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:export')")
    @Log(title = "物业费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPay sysPay)
    {
        List<SysPayVo> list = sysPayService.selectSysPayList(sysPay);
        ExcelUtil<SysPayVo> util = new ExcelUtil<SysPayVo>(SysPayVo.class);
        util.exportExcel(response, list, "物业费记录数据");
    }

    /**
     * 获取物业费记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysPayService.selectSysPayById(id));
    }

    /**
     * 新增物业费记录
     */
    @PreAuthorize("@ss.hasPermi('system:pay:add')")
    @Log(title = "物业费记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPay sysPay)
    {
        return toAjax(sysPayService.insertSysPay(sysPay));
//        return toAjax(sysPayService.addPay());
    }

    /**
     * 修改物业费记录
     */
    @PreAuthorize("@ss.hasPermi('system:pay:edit')")
    @Log(title = "物业费记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPay sysPay)
    {
        return toAjax(sysPayService.updateSysPay(sysPay));
    }


    /**
     * 缴费
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:pay:update')")
    @Log(title = "缴费", businessType = BusinessType.UPDATE)
    @GetMapping("pay/{id}/{user}")
    public AjaxResult update(@PathVariable("id") Long id,@PathVariable("user") String user)
    {
        return toAjax(sysPayService.updateSysPay(id,user));
    }

    /**
     * 删除物业费记录
     */
    @PreAuthorize("@ss.hasPermi('system:pay:remove')")
    @Log(title = "物业费记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysPayService.deleteSysPayByIds(ids));
    }
}
